<?php
/**
 * 抽奖
 * @author: jiangyong<jiangyong.go@qq.com>
 * @Date: 2023/5/18 13:49
 */

/**
 * 按照权重抽奖，最简单的抽奖
 * 100万 的概率池
 * 1     1等奖 1个
 * 2-10  2等奖 10个
 */
$pool = [
    1 => ['id' => 1, 'num' => 1],
    2 => ['id' => 2, 'num' => 10],
    3 => ['id' => 3, 'num' => 100],
];
$count = 1000000;  //概率
$index = mt_rand(1, $count);
$prize = null;
if (1 >= $index ) {
    $prize = 1;
} elseif ($index < 12) {
    $prize = 2;
} elseif ($index < 112) {
    $prize = 3;
}

var_dump($prize);